//
//  HWWebViewTopUpController.m
//  94hwan
//
//  Created by 王治庭 on 2018/10/19.
//  Copyright © 2018年 孔祥刚. All rights reserved.
//

#import "HWWebViewTopUpController.h"
#import <WebKit/WebKit.h>
//#import "HWLoginModel.h"
#import "HWHeaderView.h"
#import "HWGameWebView.h"
@interface HWWebViewTopUpController ()<WKUIDelegate,WKNavigationDelegate>

@property (strong, nonatomic) HWHeaderView *header;


@end

@implementation HWWebViewTopUpController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
   //  NSString *urlStr = [NSString stringWithFormat:@"%@?ct=h5apppay&uid=%@", [HWGlobalConst baseUrl], [HWLocallyStoredData getLoginUserID]];
    
    
    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
    
    
    
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",[HWLocallyStoredData getLoginUserID],tStr,@"fsd213ewdsadqwe2121213edsad"];
    
    NSString *signMD5 = [WMUtil md5HexDigest:sign];
     NSString *urlStr = [NSString stringWithFormat:@"%@api/app/v3/?ct=coin&uid=%@&t=%@&sign=%@&language=%@", [HWOCGlobalConst baseUrl], [HWLocallyStoredData getLoginUserID],tStr,signMD5,[HWjianzhiduiObject returnLanguageAcquisition]];
    
    //
    NSLog(@"%@", urlStr);
//
//    NSURL *url = [NSURL URLWithString:urlStr];
//
//    [[UIApplication sharedApplication] openURL:url];
//
//    self.header = [HWHeaderView new];
//    self.header.title.text = @"平台币充值";
//    __weak typeof(self) weakSelf = self;
//    self.header.leftClick = ^() {
//        [[HWViewUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
//            weakSelf.tabBarController.tabBar.hidden = YES;
//
//
//
//    };
//    [self.view addSubview:self.header];
//
//    [self.header mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.view.mas_top);
//        make.left.mas_equalTo(self.view.mas_left);
//        make.height.mas_equalTo(44 + IPHONE_STATUSBAR_HEIGHT);
//        make.right.mas_equalTo(self.view.mas_right);
//    }];
    HWGameWebView *webView = [HWGameWebView initWithUrlString:urlStr];
    
    [self.view addSubview:webView];
    
    self.header = [HWHeaderView new];
    self.header.backgroundColor = [UIColor whiteColor];
    
   
    self.header.title.text = @"平台币充值";
    self.header.title.text = [HWjianzhiduiObject keylocalization:@"平台币充值"];
    
    self.header.title.text =  [HWjianzhiduiObject keylocalization:@"平台币充值"];
    
    
    
    self.header.title.textColor = RGB(68, 68, 68);
  //   self.view.backgroundColor =   RGB(248, 248, 248);
    self.view.backgroundColor =   [UIColor whiteColor];
   

    __weak typeof(self) weakSelf = self;
    self.header.leftClick = ^() {
        [[HWViewUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
         //   weakSelf.tabBarController.tabBar.hidden = YES;
                    
    };
    [self.view addSubview:self.header];
    
     
    
    [self.header mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top);
        make.left.mas_equalTo(self.view.mas_left);
        make.height.mas_equalTo(44 + CF_StatusBarHeight);
        make.right.mas_equalTo(self.view.mas_right);
    }];
    
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.mas_equalTo(self.header.mas_bottom);
       
      //   make.top.mas_equalTo(self.header.mas_bottom).offset(20);
        
        
        make.left.mas_equalTo(self.view.mas_left);
        make.bottom.mas_equalTo(self.view.mas_bottom);
        make.right.mas_equalTo(self.view.mas_right);
    }];
    
   
//    self.header.title.textColor = RGB(51, 51, 51);
}

//#pragma mark - WKNavigationDelegate
//// 页面开始加载时调用
//- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
//    [SVProgressHUD show];
//    DLog(@"web.Start==========%f",webView.scrollView.contentSize.height);
//}

//// 当内容开始返回时调用
//- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
//    DLog(@"web.Commit==========%f",webView.scrollView.contentSize.height);
//    __weak typeof (self) weakSelf = self;
//    dispatch_async(dispatch_get_main_queue(), ^{
//        weakSelf.webView.frame = CGRectMake(0,44 + IPHONE_STATUSBAR_HEIGHT, weakSelf.webView.frame.size.width, weakSelf.webView.scrollView.contentSize.height);
//        //        [weakSelf.view reloadData];
//    });
//}
//
//// 页面加载完成之后调用
//- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
//    DLog(@"web.End==========%f",webView.scrollView.contentSize.height);
//
//    if (webView.scrollView.contentSize.height < 50) {//(50为内容为空的高度)
//        [webView reload];//WKWebView经常会出现加载不出来内容的情况，所以判断如果返回内容为空，需要重载（但需要和后台商量：如果本身webview就是空内容，让他们至少给你返回1高度嘛，凡事是可以商量的撒^_^）
//    }
//    __weak typeof (self) weakSelf = self;
//    dispatch_async(dispatch_get_main_queue(), ^{
//        weakSelf.webView.frame = CGRectMake(0, 44 + IPHONE_STATUSBAR_HEIGHT, weakSelf.webView.frame.size.width, weakSelf.webView.scrollView.contentSize.height);
//        //        [weakSelf reloadData];
//        [SVProgressHUD dismiss];
//    });
//
//    //修改字体大小 300%
//    [ webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '95%'" completionHandler:nil];
//    [ webView evaluateJavaScript:@"document.getElementsByTagName('header')[0].style.webkitTextSizeAdjust= '120%'" completionHandler:nil];
//}
//
//// 页面加载失败时调用
//- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{
//
//}
//
//// 接收到服务器跳转请求之后调用
//- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation{
//
//}
//
//// 在收到响应后，决定是否跳转
//- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
//
//    NSLog(@"%@",navigationResponse.response.URL.absoluteString);
//    //允许跳转
//    decisionHandler(WKNavigationResponsePolicyAllow);
//    //不允许跳转
//    //decisionHandler(WKNavigationResponsePolicyCancel);
//}
//
//// 在发送请求之前，决定是否跳转
//- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
//
//    NSLog(@"%@",navigationAction.request.URL.absoluteString);
//    //允许跳转
//    decisionHandler(WKNavigationActionPolicyAllow);
//    //不允许跳转
//    //decisionHandler(WKNavigationActionPolicyCancel);
//}
//
//#pragma mark - WKUIDelegate
//// 创建一个新的WebView
//- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{
//    return [[WKWebView alloc]init];
//}
//
//// 输入框
//- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * __nullable result))completionHandler{
//    completionHandler(@"http");
//}
//
//// 确认框
//- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler{
//    completionHandler(YES);
//}
//
//// 警告框
//- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler{
//    NSLog(@"%@",message);
//    completionHandler();
//}
//
//
//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
 
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

@end
